/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models.DAOs;

import DBConnection.ConnectionFactory;
import Models.Comment;
import java.lang.Exception;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Comment_DAO {
    
    public boolean addComment(Comment comment){
        try{
            
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1;
            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO comments(comment, customerID, productID) VALUES (?,?,?)");
            
            pstmt.setString(i, comment.getComment());
            pstmt.setInt(i, comment.getCustomerID());
            pstmt.setInt(i, comment.getProductID());
            pstmt.executeUpdate();
            
            return true;
        }
        catch(SQLException e){
            e.printStackTrace();
            return false;
        }
    }
    public boolean updateComment(Comment comment){
        
        try{
        
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1;
            PreparedStatement pstmt = conn.prepareStatement("UPDATE comments SET comment = ? WHERE commentID = ?");
            pstmt.setString(i++,comment.getComment());
            pstmt.setInt(i++,comment.getCommentID());
            return true;
        }
        catch(SQLException e){     
            e.printStackTrace();
            return false;
        }
    
    }
    public boolean updateCommentStatus(int commentID, int status){
    
        try{
        
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1;
            PreparedStatement pstmt = conn.prepareStatement("UPDATE comments SET status = ? WHERE commentID = ?");
            pstmt.setInt(i++,commentID);
            pstmt.setInt(i++,status);
            return true;
        }
        catch(SQLException e){
        
            e.printStackTrace();
            return false;
        }
        
    }
}
